import config from './config'
function request(path, data = {}, method = "GET") {
  return new Promise((resolve, reject) => {
    wx.request({
      url: config.host + path,
      // url: config.mobileHost + path,
      method,
      data,
      header:{
        // 设置请求头，我们可以把cookie拿到设置上
        cookie:'MUSIC_U=70b47adff51925b9b0bf486cbf55a1ef65bb4f96c094bc2041c3a7654ed2d273519e07624a9f0053a1ad7bdb0ce0a2cbab32a3c7d1dc2569e5b43202ed1f63ead80dde7e4910dddda0d2166338885bd7; Max-Age=1296000; Expires=Mon, 19 Sep 2022 03:31:03 GMT; Path=/; Domain=.music.163.com; HTTPOnly'
      },
      success: (res) => {
        // console.log(res)
        // cookie是再res里面的
        // 我们需要在这判定是不是登录操作，如果是登录操作
        // 需要把res里面的cookie信息保存起来，后续添加到header
        if(data.isLogin){
          wx.setStorageSync('cookie_key', res.cookies)
        }
        resolve(res.data)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

export default request


// request(路径,参数,请求方式)